class code4 {
    public int characterReplacement(String s, int k) {
        int[] hash = new int[26];
        int left=0,right=0;
        int maxch = 0;
        int ret = 0;
        int n = s.length();
        while(right<n) {
            //进窗口
            hash[s.charAt(right)-'A']++;
            maxch = Math.max(maxch,hash[s.charAt(right)-'A']);
            //判断
            if(right-left+1-maxch>k) {
                //出窗口
                hash[s.charAt(left)-'A']--;
                left++;
            }
            //更新结果
            ret = Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }
}